import type { LoginResult } from '@/types/api/index'
import { http } from '@/utils/http'

type LoginWxMinParams = {
  code: string
  encryptedData?: string
  iv?: string
}
// 新学未新接口
//用户反馈
export const xxwFeedbackApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/user/feedback',
    data,
  })
}
//对话大模型
export const newChatApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/dialogue/new_chat',
    data,
  })
}
// 云私教默认问题
export const defaultQuestionApi = (data) => {
  return http({
    method: 'GET',
    url: '/xxw/sp/dialogue/default_question',
    data,
  })
}
//跟读-每日学习结束打分详情
export const scoreInfoApi = (data) => {
  return http({
    method: 'GET',
    url: '/xxw/score/info',
    data,
  })
}
//跟读-朗读声音记录更新
export const readAudioSaveApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/read/audio_save',
    data,
  })
}
//跟读-课程状态更新
export const readStatusUpdate = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/read/lesson_read_status_update',
    data,
  })
}
//选择我使用的教材
export const delPlansApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/plan/del',
    data,
  })
}
//所有教材列表
export const getBookListAPi = () => {
  return http({
    method: 'GET',
    url: '/xxw/sp/book/list',
  })
}
//我的绑定教材列表
export const getMyBookListAPi = () => {
  return http({
    method: 'GET',
    url: '/xxw/sp/book/bind_list',
  })
}
//选择我使用的教材
export const selectBookApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/book/select',
    data,
  })
}
//绑定教材
export const bindBookApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/book/bind',
    data,
  })
}

//朗读系统设置
export const uploadSettingApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/user/playback_setting',
    data,
  })
}
//朗读系统设置详情
export const getSettingAPi = () => {
  return http({
    method: 'GET',
    url: '/xxw/sp/user/playback_setting_info',
  })
}
//学习计划新增
export const addPlanApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/plan/add',
    data,
  })
}
//获取学习计划
export const getPlanInfoAPi = (data) => {
  return http({
    method: 'GET',
    url: '/xxw/sp/plan/info',
    data,
  })
}
//更新学习计划
export const updatePlanApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/plan/update',
    data,
  })
}

//获取每日学习的列表
export const getDailyPlanApi = (data) => {
  return http({
    method: 'GET',
    url: '/xxw/sp/listen/day_learn_list',
    data,
  })
}
//早晚听-课程状态更新
export const updatePlanStatusApi = (data) => {
  return http({
    method: 'POST',
    url: '/xxw/sp/listen/lesson_listen_status_update',
    data,
  })
}
/**
 * 小程序登录
 * @param data 请求参数
 */
export const postLoginWxMinAPI = (data: LoginWxMinParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login/wxMin',
    data,
  })
}

/**
 * 小程序登录
 * @param data 请求参数
 */
export const getMemberAddressAPI = (data: LoginWxMinParams) => {
  return http<LoginResult>({
    method: 'GET',
    url: '/login/get',
    data,
  })
}

// 获取我创建的智能体列表
export const getMyAgents = (data) => {
  return http({
    method: 'GET',
    url: '/enteacher/agents/my',
    data,
  })
}

// 获取最近访问的智能体列表
export const getRecent = (data) => {
  return http({
    method: 'GET',
    url: '/enteacher/agents/recent',
    data,
  })
}

// 获取推荐智能体列表
export const getRecommend = (data) => {
  return http({
    method: 'GET',
    url: '/enteacher/agents/recommend',
    data,
  })
}

// 根据ID获取智能体详细信息
export const getDetailById = (id) => {
  return http({
    method: 'GET',
    url: `/enteacher/agents/${id}`,
  })
}

// 提交一次智能体使用记录
export const setUsage = (id) => {
  return http({
    method: 'POST',
    url: `/enteacher/agents/${id}/usage`,
  })
}

// Ai对话
export const getChat = (data) => {
  return http({
    method: 'POST',
    url: '/enteacher/aichat',
    data,
    type: 'normal',
  })
}

// 提交智能体
export const submitAgents = (data) => {
  return http({
    method: 'POST',
    url: '/enteacher/agents',
    data,
  })
}

// 获取达人对话详细内容
export const getDialogueTopicDetail = (data: any) => {
  return http({
    method: 'GET',
    url: `/enteacher/dialogue/topic/${data.id}`,
  })
}

// 获取达人对话列表
export const getDialogueTopicList = (data: any) => {
  return http({
    method: 'GET',
    url: `/enteacher/dialogue/topics?grade=${data.grade}`,
    data,
  })
}

// 获取场景练习场景列表
export const getScenes = (data: any) => {
  return http({
    method: 'GET',
    url: '/enteacher/scene',
    data,
  })
}

// 获取场景练习详情或换一批
export const getSceneDetailById = (id: Number, data: any) => {
  return http({
    method: 'GET',
    url: `/enteacher/scene/detail/${id}`,
    data,
  })
}

// 根据ID删除智能体
export const deleteAgentById = (id) => {
  return http({
    method: 'DELETE',
    url: `/enteacher/agents/${id}`,
  })
}

// 修改智能体
export const updateAgent = (data: any) => {
  return http({
    method: 'PUT',
    url: '/enteacher/agents',
    data,
  })
}
// 获取场景练习详情
export const getQuestionsById = (id: Number) => {
  return http({
    method: 'GET',
    url: `/enteacher/agents/questions/${id}`,
  })
}

// 获取用户使用过的场景列表
// export const getUserScene = (data: any) => {
//   return http({
//     method: 'GET',
//     url: '/enteacher/user/userScene',
//     data,
//   })
// }

// 查询用户是否绑定过设备SN
export const ifUserSn = () => {
  return http({
    method: 'GET',
    url: '/enteacher/user/userSn',
  })
}

// 用户绑定设备SN
export const bindUserSn = (sn) => {
  return http({
    method: 'POST',
    url: `/enteacher/user/userSn/${sn}`,
  })
}

//查询当前智能体是否点赞
export const selectIsVote = (id) => {
  return http({
    method: 'GET',
    url: `/enteacher/agents/vote/me/${id}`,
  })
}

// 获取年级列表
// export const getGradesList = () => {
//   return http({
//     method: 'GET',
//     url: `/enteacher/system/grades`,
//   })
// }

// 点踩
export const voteDown = (id) => {
  return http({
    method: 'POST',
    url: `/enteacher/agents/vote/down/${id}`,
  })
}

// 点赞
export const voteUp = (id) => {
  return http({
    method: 'POST',
    url: `/enteacher/agents/vote/up/${id}`,
  })
}

// 获取年级列表
export const getGradesApi = (data) => {
  return http({
    method: 'GET',
    url: `/enteacher/system/grades?bar=${data}`,
  })
}

// 点踩
export const toDown = (id) => {
  return http({
    method: 'POST',
    url: `/enteacher/scene/detail/thumbDown/${id}`,
  })
}

// 点赞
export const toUp = (id) => {
  return http({
    method: 'POST',
    url: `/enteacher/scene/detail/thumbUp/${id}`,
  })
}

// 达人对话，插入对话记录
export const insertChart = (data) => {
  return http({
    method: 'POST',
    url: `/enteacher/user/userTalent`,
    data: data,
  })
}

// 达人对话，删除历史记录
export const deleteChart = (id) => {
  return http({
    method: 'DELETE',
    url: `/enteacher/user/userTalent/${id}`,
  })
}

// 达人对话，查询历史记录
export const selectChart = (id) => {
  return http({
    method: 'GET',
    url: `/enteacher/user/userTalent/${id}`,
  })
}

// 英语自由说列表
export const freeList = (id) => {
  return http({
    method: 'GET',
    url: `/enteacher/free`,
  })
}

// 英语自由说列表换一批
export const freeNext = (data) => {
  return http({
    method: 'GET',
    url: `/enteacher/free/next?freeId=${data.freeId}&page=${data.page}&pageSize=${data.pageSize}`,
  })
}

// 英语自由说置顶的任务
export const getFreeTop = () => {
  return http({
    method: 'GET',
    url: `/enteacher/free/top`,
  })
}

// 英语自由说详细内容
export const getFreeContent = (id) => {
  return http({
    method: 'GET',
    url: `/enteacher/free/content/${id}`,
  })
}

// 上传音频
export const uploadAudio = (data) => {
  return http({
    method: 'POST',
    url: `/xm/platform/base64_upload`,
    data,
  })
}

// 更新用户信息
export const updateUser = (data) => {
  return http({
    method: 'POST',
    url: `/api/update-user?id=${data.owner}/${data.name}`,
    type: 'common',
    data,
  })
}

// 获取用户信息
export const getAccount = () => {
  return http({
    method: 'GET',
    url: `/api/get-account`,
    type: 'common',
  })
}

//获取小学初中年级
export const getAllGrades = () => {
  return http({
    method: 'GET',
    url: `/enteacher/system/all_grades`,
  })
}
// 意见反馈接口
export const userFeedBack = (data) => {
  return http({
    method: 'POST',
    url: `/enteacher/user/userFeedBack`,
    data,
  })
}
